package mvc;

import java.util.PriorityQueue;

import engine.*;

/**
 * 
 * The Model component of the MVC system.
 * All direct interfacing with the engine should be here.
 * 
 * @author Dylan Swiggett
 *
 */
public class Model extends Thread{
	APOPS engine;
	
	NPolygon polygon;	//TESTING
	
	public Model(){
		engine = new APOPS();	//Some day...
		
		/*
		 * Vector testing
		 */
		
		polygon = new NPolygon();
//		for (double i = Math.PI * 2; i > 0; i-= Math.PI * 2 / 100){
//			polygon.addVertex(100 + 100 * Math.cos(i), 100 + 100 * Math.sin(i));
//		}
		
//		polygon.addVertex(25, 100);
//		polygon.addVertex(50, 100);
//		polygon.addVertex(75, 50);
//		polygon.addVertex(100, 75);
//		polygon.addVertex(125, 110);
//		polygon.addVertex(175, 100);
//		polygon.addVertex(200, 50);
//		polygon.addVertex(200, 0);
//		polygon.addVertex(150, 0);
//		polygon.addVertex(100, 0);
//		polygon.addVertex(50, 0);
//		polygon.addVertex(0, 0);
		
		polygon.addVertex(120, 120);
		polygon.addVertex(120, 160);
		polygon.addVertex(140, 180);
		polygon.addVertex(140, 200);
		polygon.addVertex(110, 220);
		polygon.addVertex(140, 240);
		polygon.addVertex(180, 200);
		polygon.addVertex(160, 200);
		polygon.addVertex(160, 180);
		polygon.addVertex(180, 160);
		polygon.addVertex(200, 180);
		polygon.addVertex(220, 200);
		polygon.addVertex(260, 160);
		polygon.addVertex(260, 120);
		polygon.addVertex(220, 100);
		polygon.addVertex(200, 140);
		polygon.addVertex(160, 140);
		polygon.addVertex(160, 120);
		
//		polygon.addVertex(0, 0);
//		polygon.addVertex(0, 100);
//		polygon.addVertex(100, 100);
//		polygon.addVertex(100, 0);
//		
//		polygon.generateInnerTriangles();
//		
//		System.out.println(polygon.triangles.size());
//		
//		PriorityQueue<Angle> queue = polygon.verticesToAngles();
//		
//		while (!queue.isEmpty()){
//			System.out.println(queue.poll().getCrossProduct());
//		}
		
//		System.exit(0);
	}
	
	/**
	 * This is the main loop of the program -- should call iterate() in APOPS.
	 */
	public void run(){
		while (true){
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			engine.iterate(1);
		}
	}
}
